﻿using System;
using System.Web.UI;
using MedicalCare.DbLayer.Adaptors;
using MedicalCare.Messages;
using StructureMap;

namespace MedicalCare
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            span_msg.InnerHtml = string.Empty;
        }

        protected void btnLogin_Click(object sender, ImageClickEventArgs e)
        {
            //if (string.IsNullOrEmpty(tbUserName.Text))
            //{
            //    ShowErrMessage("用户名不能为空");
            //    return;
            //}


            //if (string.IsNullOrEmpty(tbPassword.Text))
            //{
            //    ShowErrMessage("密码不能为空");
            //    return;
            //}

            //if (!String.Equals(AppPage.CurrentValidationCode, tbCode.Text, StringComparison.CurrentCultureIgnoreCase))
            //{
            //    ShowErrMessage("验证码不正确");
            //    return;
            //}

            var message = new LoginMessage()
                              {
                                  //Name = tbUserName.Text,
                                  //Password = tbPassword.Text
                                  Name = "test",
                                  Password = "123456"
                              };
            var userAdaptor = ObjectFactory.GetInstance<IUserAdaptor>();
            var userMessage = userAdaptor.LoadCurrentUser(message);
            if (userMessage.Success)
            {
                AppPage.CurrentUser = userMessage;
                Server.Transfer("./Admin/UserList.aspx");
            }
            else
            {
                ShowErrMessage("用户验证失败");
            }
        }

        private void ShowErrMessage(string message)
        {
            span_msg.InnerHtml = " * " + message;
        }
    }
}